/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

class MAddressMAC
{
private:
	int BHtoInt(CString);
	int BHtoIntL(LPCTSTR);

	BYTE cmpAddr[6];

public:
	MAddressMAC(void);
	~MAddressMAC(void);

	BYTE addr[6];

	/*! Sets the MAC address to the value "00:00:00:00:00:00". */
	void Initialize(void);

	void LoadFromPointer(MAddressMAC*);
	void LoadFromBytePtr(BYTE*);

	/*! Returns true if the value is "00:00:00:00:00:00". */
	bool IsEmpty(void);

	/*! Returns true if the value is "FF:FF:FF:FF:FF:FF". */
	bool IsBroadcast(void);

	/*! Set the value to "FF:FF:FF:FF:FF:FF". */
	void SetAsBroadcastAddress(void);

	/* \brief Returns the MAC address as a string.

		Returns the MAC address as a string in the format "aa:bb:cc:dd:ee:ff".
	*/
	CString GetS(void);

	/* \brief Returns the MAC address as a string.

		Returns the MAC address as a string in the format "aa-bb-cc-dd-ee-ff".
	*/
	CString GetSD(void);

	/*! \brief Set the MAC address from the supplied string.

		Loads a MAC address from a string which obey one of the following formats:
			- "aa:bb:cc:dd:ee:ff"
			- "aa-bb-cc-dd-ee-ff"
			.
	*/
	bool LoadFromString(CString);

	/* \brief Compares two MAC addresses.

		Comparison this MAC address with the supplied one and returns:
			- -1 if is "lower"
			-  0 if the addresses are the same
			-  1 if is "higher" or the supplied one is a NULL pointer
			.
	*/
	int Compare(MAddressMAC*);

	/* \brief Check only for equality.

		Should be faster then Compare
	*/
	bool IsEqualWith(MAddressMAC*);

	/*! Returns true if it holds a broadcast address */
	bool IsBroadcastAddress(void);

	/*! Returns true if it holds a multicast address */
	bool IsMulticastAddress(void);

	/*! Returns true if it holds a GVRP destination MAC */
	bool IsGvrpDestinationMAC(void);
	/*! Returns true if it holds a GVRP destination MAC */
	bool IsGmrpDestinationMAC(void);
	/*! Returns true if it holds an IEEE 802.1D-2004 STP BPDU destination MAC (Bridge Group Address)*/
	bool IsStpDestinationMAC(void);
};
